package collect

import (
	"github.com/gin-gonic/gin"
	"goskeleton/app/model"
	"goskeleton/app/utils/response"
	"strconv"
)

type CollectController struct {
}

func (c CollectController) GetCollect(context *gin.Context) {
	//获取collect_open_id
	collectOpenId := context.Query("collect_open_id")
	productIds := model.CreateCollectFactory("mysql").GetCollect(collectOpenId)

	response.Success(context, "获取收藏商品成功", productIds)
}

func (c CollectController) AddCollect(context *gin.Context) {

	collectOpenId := context.Query("collect_open_id")
	productId := context.Query("product_id")

	//转换productId为int
	productIdInt, _ := strconv.Atoi(productId)

	model.CreateCollectFactory("mysql").AddCollect(collectOpenId, productIdInt)

	response.Success(context, "添加收藏成功", nil)

}

func (c CollectController) CancelCollect(context *gin.Context) {
	collectOpenId := context.Query("collect_open_id")
	productId := context.Query("product_id")
	model.CreateCollectFactory("mysql").CancelCollect(collectOpenId, productId)
	response.Success(context, "取消收藏成功", nil)

}

func (c CollectController) MyCollect(context *gin.Context) {
	collectOpenId := context.Query("collect_open_id")

	collectList, _ := model.CreateCollectFactory("mysql").GetMyCollect(collectOpenId)

	response.Success(context, "获取我的收藏成功", collectList)

}
